/***************************** BEGIN LICENSE BLOCK ***************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/MPL-1.1.html
 
 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the License.
 
 The Original Code is the "EO-SPS Framework".
 
 The Initial Developer of the Original Code is Spotimage S.A.
 Portions created by the Initial Developer are Copyright (C) 2007
 the Initial Developer. All Rights Reserved.
 
 Contributor(s): 
    Alexandre Robin <alexandre.robin@spotimage.fr>
 
******************************* END LICENSE BLOCK ***************************/

package com.spotimage.eosps;

import org.w3c.dom.Element;
import org.vast.ows.OWSException;
import org.vast.ows.sps.SPSException;
import org.vast.ows.swe.SWERequestWriter;
import org.vast.xml.DOMHelper;


/**
* <p><b>Title:</b><br/>
* EO-SPS SubmitSegmentByID Request Writer v2.0
* </p>
*
* <p><b>Description:</b><br/>
* Provides methods to generate an XML EO-SPS SubmitSegmentByID
* request based on values contained in a SubmitSegmentByIDRequest object
* for version 2.0
* </p>
*
* <p>Copyright (c) 2010</p>
* @author Alexandre Robin <alexandre.robin@spotimage.fr>
* @date July 19, 2010
* @version 1.0
*/
public class SubmitSegmentByIDWriterV20 extends SWERequestWriter<SubmitSegmentByIDRequest>
{

	/**
	 * KVP Request
	 */
	@Override
	public String buildURLQuery(SubmitSegmentByIDRequest request) throws OWSException
	{
		throw new SPSException(noKVP + "SPS 2.0 " + request.getOperation());
	}


	/**
	 * XML Request
	 */
	@Override
	public Element buildXMLQuery(DOMHelper dom, SubmitSegmentByIDRequest request) throws OWSException
	{
		dom.addUserPrefix("eosps", EOConstants.EOT_NAMESPACE);

		// root element
		Element rootElt = dom.createElement("eosps:" + request.getOperation());
		addCommonXML(dom, rootElt, request);

		// taskID
		dom.setElementValue(rootElt, "eosps:task", request.getTaskID());
		
		// segmentIDs
		for (String segmentID: request.getSegmentIDs())
			dom.setElementValue(rootElt, "+eosps:segmentID", segmentID);
	
		return rootElt;
	}
}